import api from './index'

export const executionApi = {
  // 获取执行记录列表
  getExecutions(params) {
    return api.get('/executions/', { params })
  },

  // 获取执行记录详情
  getExecution(id) {
    return api.get(`/executions/${id}`)
  },

  // 获取执行日志
  getExecutionLogs(id, params) {
    return api.get(`/executions/${id}/logs`, { params })
  },

  // 导出执行日志
  exportExecutionLogs(id, params) {
    return api.get(`/executions/${id}/logs/export`, { params })
  },

  // 重新执行
  retryExecution(id) {
    return api.post(`/executions/${id}/retry`)
  },

  // 验证执行结果
  verifyExecution(id) {
    return api.post(`/executions/${id}/verify`)
  },

  // 获取验证状态
  getVerificationStatus(id) {
    return api.get(`/executions/${id}/verification-status`)
  },

  // 调度延迟验证
  scheduleVerification(id, delayMinutes = 5) {
    return api.post(`/executions/${id}/schedule-verification`, null, {
      params: { delay_minutes: delayMinutes }
    })
  },

  // 批量验证执行记录
  batchVerify(executionIds) {
    return api.post('/executions/batch-verify', executionIds)
  },

  // 回滚执行
  rollbackExecution(id) {
    return api.post(`/executions/${id}/rollback`)
  },

  // 检查是否可以回滚
  checkCanRollback(id) {
    return api.get(`/executions/${id}/can-rollback`)
  },

  // 获取回滚历史
  getRollbackHistory(id) {
    return api.get(`/executions/${id}/rollback-history`)
  },

  // 批量回滚
  batchRollback(executionIds) {
    return api.post('/executions/batch-rollback', executionIds)
  },

  // 触发自动回滚
  triggerAutoRollback(id) {
    return api.post(`/executions/${id}/auto-rollback`)
  }
}
